<template>
  <div style="text-align: center">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">



      <div style="display: flex">
        <div style="flex: 1">

          <el-form-item label="手牌号" prop="handBrand" >
            <el-input v-model="form.handBrand" placeholder="请输入手牌号" />
          </el-form-item>
        </div>
      </div>
      <!--<el-row style="display: flex; justify-content: center; align-items: center;">
        <el-col span="10" style="display: flex; justify-content: center; align-items: center;">
          <el-form-item label="手牌号" prop="handBrand">
            <el-input v-model="form.handBrand" placeholder="请输入手牌号" />
          </el-form-item>
        </el-col>
      </el-row>-->
    </el-form>

    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <el-button type="primary" @click="suojiepai">解/锁</el-button>
      <el-button @click="cancel">返 回</el-button>
    </div>
  </div>
</template>

<script>
  import { listHands, getHands, delHands, addHands, updateHands ,suopai} from "@/api/module/wyw/hands";
  export default {
  name: "suopai",
    props: ['suppaihandid'], // 接收传入的 id
  dicts: ['yqg_locked_state'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单  note3: null,个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 手牌基础信息表格数据
      handsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        handBrand: null,
        handCategory: null,
        handState: null,
        lockedState: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
    //必须写监听，不然会出现id还是还是上一次的问题
    watch: {
      suppaihandid() {
        // 当 id 值发生改变时，重新获取或者刷新数据
        this.form.handBrand=this.suppaihandid[0];
        this.getList();
      },
    },
      created() {
    if(this.suppaihandid==null||this.suppaihandid==''){

      this.getList();
    }else{
      this.form.handBrand=this.suppaihandid[0];
      this.getList();
    }

      },
      methods: {
// 表单重置
        reset() {
          this.form = {
            id: null,
            handBrand: null,
            handCategory: null,
            handState: null,
            lockedState: null,
            note1: null,
            note2: null,

            note4: null,
      note5: null
    };
    this.resetForm("form");
  },

  /** 查询手牌基础信息列表 */
  getList() {
    this.loading = true;
    listHands(this.form).then(response => {
      this.handsList = response.rows;
    });
  },

  suojiepai(){
    this.getList();
    const i =this.handsList[0].lockedState;
    if(i==0){
      this.$modal.confirm('是否确认解锁？').then(function() {
      }).then(() => {
        suopai(this.form);
        this.$modal.msgSuccess("解锁成功");
        this.$emit("closeDialog"); // 触发 closeDialog 事件
        this.reset();
      }).catch(() => {});
    }else{
      this.$modal.confirm('是否确认锁定？').then(function() {
      }).then(() => {
        suopai(this.form);
        this.$modal.msgSuccess("锁定成功");
        this.$emit("closeDialog"); // 触发 closeDialog 事件
        this.reset();
      }).catch(() => {});
    }









  },
  cancel(){
    this.$emit("closeDialog"); // 触发 closeDialog 事件
    this.reset();
  }
}


}

</script>

<style scoped>

</style>
